package com.cui.project.mapper;

import com.api.common.model.entity.InterfaceInfoLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
* @author 86176
* @description 针对表【interface_info_log】的数据库操作Mapper
* @createDate 2024-10-16 12:48:44
* @Entity com.api.common.model.entity.InterfaceInfoLog
*/
public interface InterfaceInfoLogMapper extends BaseMapper<InterfaceInfoLog> {


    /**
     * 统计当前接口所以用户调用的正确与错误统计
     * @return
     */
    @Select("SELECT \n" +
            "  SUM(CASE WHEN code = 200 THEN 1 ELSE 0 END) AS success,\n" +//计算成功状态的数量。
            "  MAX(CASE WHEN code = 200 THEN createTime ELSE NULL END) AS lastSuccessTime,\n" + //获取成功状态的最后 createTime。MAX 函数会找到条件匹配时的最大时间。
            "  SUM(CASE WHEN code != 200 THEN 1 ELSE 0 END) AS fail,\n" + //计算失败状态的数量。
            "  MAX(CASE WHEN code != 200 THEN createTime ELSE NULL END) AS lastFailTime\n" + //获取失败状态的最后 createTime。
            "FROM \n" +
            "  interface_info_log\n" +
            "WHERE \n" +
            "  interface_info_id = #{interfaceInfoId} ")
    public Map<String,Object> selectHistorySuccessAndFailCount(Long interfaceInfoId );

}




